package org.feng.support;

import cn.hutool.core.bean.BeanUtil;
import org.feng.entity.SysScheduler;
import org.quartz.Job;
import org.quartz.JobExecutionContext;


/**
 * job执行
 *
 * @author : FengShuai
 * @since : 2024/6/27 9:24
 */
public abstract class AbstractJob implements Job {
    @Override
    public void execute(JobExecutionContext context) {
        long startTime = System.currentTimeMillis();
        SysScheduler data = BeanUtil.toBean(context.getMergedJobDataMap().get("data"), SysScheduler.class);
        try {
            doExecute(context, data);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        long endTime = System.currentTimeMillis();
        System.out.println("任务执行完成，耗时：" + (endTime - startTime) + "毫秒");
    }

    protected abstract void doExecute(JobExecutionContext context, SysScheduler sysScheduler) throws Exception;
}
